package com.morningstar.flow.flowable.assigne;

import com.morningstar.flow.antvX6.common.Assign;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

abstract public class AssigneeStrategyHandler {

    public static final Map<String, AssigneeStrategyHandler> ASSIGNEE_STRATEGY_HANDLER_MAP = new ConcurrentHashMap<>();

    public static AssigneeStrategyHandler getAssigneeStrategyHandler(String assignStrategy) {
        return ASSIGNEE_STRATEGY_HANDLER_MAP.get(assignStrategy);
    }

    /**
     * 获取任务执行人
     *
     * @param assign    任务执行人策略
     * @param execution 执行任务参数
     * @return 任务执行人列表
     */
    public abstract List<String> handler(Assign assign, ExecutionEntityImpl execution);

    public void register(String assignStrategy, AssigneeStrategyHandler assigneeStrategyHandler) {
        ASSIGNEE_STRATEGY_HANDLER_MAP.put(assignStrategy, assigneeStrategyHandler);
    }
}
